package com.pactera.demo.base.service.impl;

import com.pactera.demo.base.dto.UserRole;
import com.pactera.demo.base.entity.LoginUser;
import com.pactera.demo.base.entity.User;
import com.pactera.demo.base.mapper.LoginUserMapper;
import com.pactera.demo.base.mapper.UserMapper;
import com.pactera.demo.base.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户个人信息表 服务实现类
 * </p>
 *
 * @author mybatis.plus
 * @since 2020-02-27
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    private UserMapper userMapper;
    private LoginUserMapper loginUserMapper;
    @Override
    public void bindRolesToUser(List<UserRole> userRoles) {
        userRoles.stream().forEach(x -> this.userMapper.insertUserRole(x));
    }

    @Override
    public void saveUser(User user, LoginUser loginUser) {
        this.userMapper.insert(user);
        loginUser.setUserId(user.getId());
        this.loginUserMapper.insert(loginUser);
    }


    public UserServiceImpl(UserMapper userMapper, LoginUserMapper loginUserMapper) {
        this.userMapper = userMapper;
        this.loginUserMapper = loginUserMapper;
    }
}
